/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/ccjzxyxt">ccjzxyxt</a> All rights reserved.
 */
package cn.net.dckj.modules.biz.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.net.dckj.common.config.Global;
import cn.net.dckj.common.persistence.Page;
import cn.net.dckj.common.web.BaseController;
import cn.net.dckj.common.utils.StringUtils;
import cn.net.dckj.modules.biz.entity.BizSchoolCalendar;
import cn.net.dckj.modules.biz.service.BizSchoolCalendarService;

/**
 * 校历信息Controller
 * @author xzy
 * @version 2019-04-15
 */
@Controller
@RequestMapping(value = "${adminPath}/biz/bizSchoolCalendar")
public class BizSchoolCalendarController extends BaseController {

	@Autowired
	private BizSchoolCalendarService bizSchoolCalendarService;
	
	@ModelAttribute
	public BizSchoolCalendar get(@RequestParam(required=false) String id) {
		BizSchoolCalendar entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bizSchoolCalendarService.get(id);
		}
		if (entity == null){
			entity = new BizSchoolCalendar();
		}
		return entity;
	}
	
	@RequiresPermissions("biz:bizSchoolCalendar:view")
	@RequestMapping(value = {"list", ""})
	public String list(BizSchoolCalendar bizSchoolCalendar, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BizSchoolCalendar> page = bizSchoolCalendarService.findPage(new Page<BizSchoolCalendar>(request, response), bizSchoolCalendar); 
		model.addAttribute("page", page);
		return "modules/biz/bizSchoolCalendarList";
	}

	@RequiresPermissions("biz:bizSchoolCalendar:view")
	@RequestMapping(value = "form")
	public String form(BizSchoolCalendar bizSchoolCalendar, Model model) {
		model.addAttribute("bizSchoolCalendar", bizSchoolCalendar);
		return "modules/biz/bizSchoolCalendarForm";
	}

	@RequiresPermissions("biz:bizSchoolCalendar:edit")
	@RequestMapping(value = "save")
	public String save(BizSchoolCalendar bizSchoolCalendar, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bizSchoolCalendar)){
			return form(bizSchoolCalendar, model);
		}
		bizSchoolCalendarService.save(bizSchoolCalendar);
		addMessage(redirectAttributes, "保存校历信息成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizSchoolCalendar/?repage";
	}
	
	@RequiresPermissions("biz:bizSchoolCalendar:edit")
	@RequestMapping(value = "delete")
	public String delete(BizSchoolCalendar bizSchoolCalendar, RedirectAttributes redirectAttributes) {
		bizSchoolCalendarService.delete(bizSchoolCalendar);
		addMessage(redirectAttributes, "删除校历信息成功");
		return "redirect:"+Global.getAdminPath()+"/biz/bizSchoolCalendar/?repage";
	}

}